#ifndef __DM6_PROTOCOL_H__
#define __DM6_PROTOCOL_H__


#include "base_protocol.h"


#define DM6_PACKET_HEADLEN      64
#define DM6_FIX_MSG_LEN         512


enum CMD_TYPE:uint16_t                      //请求方向的消息类型
{
        CMD_IS_SERVER_ACTIVE            = 0,
        CMD_LOGIN                       = 1,
        CMD_LOGOUT                      = 2,
        CMD_STMT_ALLOCATE               = 3,
        CMD_STMT_ALLOCATE_AUTO          = 2051,
        CMD_STMT_FREE                   = 4,
        CMD_STMT_FREE_AUTO              = 2052,
        CMD_PREPARE                     = 5,
        CMD_PREPARE_AUTO                = 2053,
        CMD_EXECUTE                     = 6,
        CMD_EXECUTE_AUTO                = 2054,
        CMD_FETCH                       = 7,
        CMD_FETCH_AUTO                  = 2055,
        CMD_COMMIT                      = 8,
        CMD_ROLLBACK                    = 9,
        CMD_GET_SQLSATE                 = 10,
        CMD_CANCLE                      = 11,
        CMD_POSITION                    = 12,
        CMD_UNPREPARE                   = 13,
        CMD_PUT_DATA                    = 14,
        CMD_PUT_DATA_AUTO               = 2062,
        CMD_GET_DATA                    = 15,
        CMD_GET_DATA_AUTO               = 2063,
        CMD_CREATE_BLOB                 = 16,
        CMD_CREATE_BLOB_AUTO            = 2064,
        CMD_CLOSE_STMT                  = 17,
        CMD_CLOSE_STMT_AUTO             = 2065,
        CMD_TIME_OUT                    = 18,
        CMD_CURSOR_PREPARE              = 19,
        CMD_CURSOR_EXECUTE              = 20,
        CMD_EXPLAIN                     = 21,
        CMD_PLAN_START                  = 22,
        CMD_PLAN_START_AUTO             = 2070,
        CMD_PLAN_ADD_ERRCODES           = 23,
        CMD_PLAN_ADD_ERRCODES_AUTO      = 2071,
        CMD_PLAN_DEL_ERRCODES           = 24,
        CMD_PLAN_DEL_ERRCODES_AUTO      = 2072,
        CMD_PUT_SUBSTR                  = 25,
        CMD_GET_SUBSTR                  = 26,
        CMD_CURSOR_SET_NAME             = 27,
        CMD_CURSOR_SET_NAME_AUTO        = 2075,
        CMD_GET_ROW_NUM                 = 28,
        CMD_BLOB_SET_BYTES              = 33,
        CMD_TEXT_GET_LEN                = 34,
        CMD_TEXT_GET_SUB_STR            = 35,
        CMD_TEXT_SET_STR                = 36,
        CMD_BLOB_TRUNCATE               = 37,
        CMD_TEXT_TRUNCATE               = 38,
        CMD_BLOB_GET_LEN                = 39,
        CMD_BLOB_GET_SUB_STR            = 40,
        CMD_BULK_INSERT                 = 41,
        CMD_DUPLICATE_BULK_INSERT       = 42,
        CMD_DESCRIBE_DTYPE              = 43,
        CMD_MORE_RESULT                 = 44,
        CMD_MORE_RESULT_AUTO            = 2092,
        CMD_PREPARE_EX                  = 46,
        CMD_PREPARE_EX_AUTO             = 2094,
        CMD_SET_BCP                     = 47,
        CMD_BCP_INSERT                  = 48,
        CMD_CLR_BCP                     = 49,
        CMD_RESET_SESS                  = 50,
        CMD_BLOB_SET_BYTES_NEW          = 52,
        CMD_BLOB_SET_BYTES_NEW_AUTO     = 2100,
        CMD_TEXT_GET_LEN_NEW            = 53,
        CMD_TEXT_GET_LEN_NEW_AUTO       = 2101,
        CMD_TEXT_GET_SUB_STR_NEW        = 54,
        CMD_TEXT_GET_SUB_STR_NEW_AUTO   = 2102,
        CMD_TEXT_SET_STR_NEW            = 55,
        CMD_TEXT_SET_STR_NEW_AUTO       = 2103,
        CMD_BLOB_TRUNCATE_NEW           = 56,
        CMD_BLOB_TRUNCATE_NEW_AUTO      = 2104,
        CMD_TEXT_TRUNCATE_NEW           = 57,
        CMD_TEXT_TRUNCATE_NEW_AUTO      = 2105,
        CMD_BLOB_GET_LEN_NEW            = 58,
        CMD_BLOB_GET_LEN_NEW_AUTO       = 2106,
        CMD_BLOB_GET_SUB_STR_NEW        = 59,
        CMD_BLOB_GET_SUB_STR_NEW_AUTO   = 2107,
        CMD_XA                          = 60,
        CMD_CHK_TRX                     = 106,
        CMD_SYNC_SUSP_TRX               = 108,
        CMD_SYNC_HEUR_COMMIT            = 109,
        CMD_SYNC_HEUR_ROLLBACK          = 110,
        CMD_STARTUP_AUTO                = 2248,
        CMD_SET_APP_NAME                = 209,
        CMD_SET_COMPRESS                = 210

};

enum RET_TYPE:uint16_t                      //返回方向的消息类型
{
    RET_OTHER                           = 0, 
    RET_BASE                            = 127,
    RET_DDL_CDB                         = 128,
    RET_DDL_CTAB                        = 129,
    RET_DDL_DTAB                        = 130,
    RET_DDL_CVIEW                       = 131,
    RET_DDL_DVIEW                       = 132,
    RET_DDL_CIND                        = 133,
    RET_DDL_DIND                        = 134,
    RET_DDL_CUSR                        = 135,
    RET_DDL_DUSR                        = 136,
    RET_DDL_CROL                        = 137,
    RET_DDL_DROL                        = 138,
    RET_DDL_DROP                        = 139,
    RET_DDL_ALTDB                       = 140,
    RET_DDL_ALTUSR                      = 141,
    RET_DDL_CFUNC                       = 142,
    RET_DDL_CPROC                       = 143,
    RET_DDL_GRANT                       = 144,
    RET_DDL_REVOKE                      = 145,
    RET_DDL_ALTTAB                      = 146,
    RET_COMMIT                          = 147,
    RET_ROLLBACK                        = 148,
    RET_EXPLAIN                         = 149,
    RET_SET_TRAN                        = 150,
    RET_SAVEPNT                         = 151,
    RET_SET_CURDB                       = 152,
    RET_SET_CURSCH                      = 153,
    RET_LOCK_TAB                        = 154,
    RET_DDL_AUDIT                       = 155,
    RET_DML_INSERT                      = 157,
    RET_DML_DELETE                      = 158,
    RET_DML_UPDATE                      = 159,
    RET_DML_SELECT                      = 160,
    RET_DML_SELECT_INTO                 = 161,
    RET_DLM_CALL                        = 162,
    RET_LOGIN                           = 163,
    RET_NEED_DATA                       = 165,
    RET_SET_SESS_TRAN                   = 166,
    RET_FETCH_NOT_OVER                  = 167,
    RET_EXEC_PROC                       = 178,
    RET_SIMPLE                          = 187,
    RET_DDL_CSCHEMA                     = 188,
    RET_PLAN_ERRCODE                    = 189,
    RET_DDL_ALTTRIG                     = 190,
    RET_DDL_DROP_TABLE                  = 191,
    RET_DDL_DROP_INDEX                  = 192,
    RET_DDL_DROP_VIEW                   = 193,
    RET_DML_TRCT                        = 194,
    RET_SET_IDENIINS                    = 195,
    RET_DDL_CSEQ                        = 196,
    RET_DML_CURSOR_DECLARE              = 197,
    RET_DML_CURSOR_OPEN                 = 198,
    RET_DML_CURSOR_CLOSE                = 199,
    RET_DML_CURSOR_UPDATE               = 200,
    RET_DML_CURSOR_DELETE               = 201,
    RET_DML_CURSOR_FETCH                = 202,
    RET_DML_CURSOR_SEEK                 = 203,
    RET_DDL_CLGN                        = 204,
    RET_DDL_ALTLGN                      = 205,
    RET_DDL_CCONIND                     = 206,
    RET_DDL_DCONIND                     = 207,
    RET_DDL_ALTCONIND                   = 208,
    RET_STARTUP                         = 228

};


namespace secsmart_protocol
{
    class DM6Protocol: public BaseProtocol
    {
        public:
            DM6Protocol()
            {
                databaseName = DBNAME_DAMENG;
            }

            virtual DETECT_RESULT parse(secsmart_session::session_sptr session, const uint8_t *buf, size_t size, bool is_forward);

            std::string extendInfo();

        private:
            bool isTrueCmd(const uint16_t cmdType);
            void parseVersion(const uint8_t *buf,size_t &position, size_t size);
            

        private:
            std::string versionInfo = "";

            
    };
}





















#endif